package com.rush.paylog;

import java.util.Timer;
import java.util.TimerTask;

import com.ab.activity.AbActivity;
import com.ab.db.storage.AbSqliteStorage;
import com.rush.paylog.db.DBInsideHelper;
import com.rush.paylog.db.DBSDHelper;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends  AbActivity implements OnClickListener{
	
	//数据库操作类
		public AbSqliteStorage mAbSqliteStorage = null;
		
		private Button btnOutlay,btnIncome;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        btnOutlay=(Button) findViewById(R.id.btn_outlay);
        btnIncome=(Button) findViewById(R.id.btn_income);
        
        btnOutlay.setOnClickListener(this);
        btnIncome.setOnClickListener(this);
        
        initDb();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    private static Boolean isExit = false;  
    private static Boolean hasTask = false;  
    private Timer tExit = new Timer();  
    private TimerTask task = new TimerTask() {  
        @Override 

        public void run() {  
            isExit = true;  
            hasTask = true;  
        }  
    };  
    @Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) {  
        if (keyCode == KeyEvent.KEYCODE_BACK) {  
            if(isExit == false ) {  
                isExit = true;  
                showToast("再按一次退出程序");  
                if(!hasTask) {  
                    tExit.schedule(task, 2000);  
                }  
            } else {  
                finish();  
                System.exit(0);  
            }  
        }  
        return false;  

    } 
    
    public void initDb(){
    	try {
    		DBSDHelper dbsdHelper=	new DBSDHelper(MainActivity.this);
    		dbsdHelper.tests();
    		
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
    	
    }


	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		if (v.getId()==R.id.btn_outlay) {//支出
			
			Log.i("ou", ">>>>btn_outlay>>>>");
			
		}
		
		if (v.getId()==R.id.btn_income) {//收入
			Log.i("ou", ">>>>btn_income>>>>");
		}
		
	}
    
}
